﻿@*
    * ---------------------------------------------------
    * 作者: MTQ
    * 日期： 2021/5/14 14:28:20
    * ---------------------------------------------------
*@
@using MTQ.BLL;
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout_lay_admin.cshtml";
}
<div class="layuimini-container">

    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend formeld="html" formeld_key="legend">@ViewBag.TitleSearch</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form" action="#">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">@ViewBag.SearchKey</label>
                            <div class="layui-input-inline">
                                <input type="text" name="keyword" id="keyword" autocomplete="off" class="layui-input">
                            </div>
                        </div>





                        <div class="layui-inline">
                            <button id="btn-search" class="layui-btn " lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> <span formeld="html" formeld_key="searchbutton">@ViewBag.Search </span></button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
        <button type="button" class="layui-btn" id="btnupload" style="display:none"><i class="layui-icon"></i>上传文件</button>
        <table class="layui-hide formeldboard" id="currentTableId" lay-filter="currentTableFilter"></table>
        <script type="text/html" id="currentTableBar">
            <a ex_btn="ex_edit" class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">详情</a>
        </script>
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button ex_btn="ex_add" class="layui-btn layui-btn-sm data-add-btn" lay-event="add"> @ViewBag.Add </button>
                <button ex_btn="ex_upload" class="layui-btn layui-btn-sm data-add-btn" lay-event="upload"> @ViewBag.Upload </button>
                <button ex_btn="ex_delete" class="layui-btn layui-btn-sm layui-btn-danger data-count-delete" lay-event="delete">@ViewBag.Delete</button>
                <button ex_btn="ex_export" class="layui-btn layui-btn-sm layui-btn-normal" lay-event="export">  @ViewBag.Export </button>
            </div>
        </script>
    </div>
</div>
<script type="text/javascript">
    var table;
    var reloadTable = function (sortField, sortType) {
        var startdate = $("#startdate").val();
        var enddate = $("#enddate").val();
        var keyword = $("#keyword").val();

        table.reload('currentTableId', {
            where: { //设定异步数据接口的额外参数，任意设
                keyword: keyword,
                startdate: startdate,
                enddate: enddate,
                sortField: sortField,
                sortType: sortType
            }
        });
    }

    layui.use(['form', 'table', 'upload', 'laydate'], function () {
        var $ = layui.jquery,
            laydate = layui.laydate,
            form = layui.form;
        var upload = layui.upload;
        window.table = layui.table;

        //指定允许上传的文件类型
        upload.render({
            elem: '#btnupload'
            , url: '/Log_Login/UploadFile' //改成您自己的上传接口
            , accept: 'file' //普通文件
            , done: function (res) {
                if (res.success) {
                    layer.msg('上传成功');
                    reloadTable('Log_Id', 'asc');
                } else {
                    layer.msg('上传失败');
                }
            }
        });

        laydate.render({
            elem: '#startdate'
        });
        laydate.render({
            elem: '#enddate'
        });

        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'upload') {  // 监听添加操作
                $("#btnupload").click();

            } else if (obj.event === 'add') {
                var index = layer.open({
                    title: '添加',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    area: ['800px', '90%'],
                    content: '/Log_Login/Create',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId');
                var data = checkStatus.data;
                layer.confirm('确定要禁用选中的账户吗？', function () {
                    var arrId = [];
                    for (var i = 0; i < data.length; i++) {
                        arrId.push(data[i].Log_Id);
                    }
                    var strIds = arrId.join(',');
                    $.ajax({
                        url: '/Log_Login/ActivateSwich',
                        type: 'post',
                        dataType: 'text',
                        data: { "primarykeys": strIds },
                        success: function (resp) {
                            var json = eval('(' + resp + ')');
                            layer.alert(json.Message);
                            reloadTable('Log_Id', 'asc');
                        },
                        error: function (resp) {
                            layer.alert("对不起出错了");
                        }
                    })
                })
            } else if (obj.event === 'export') {
                var keyword = $("#keyword").val();
                var startdate = $("#startdate").val();
                var enddate = $("#enddate").val();
                var url = "/Log_Login/Export?keyword=" + keyword + "&startdate=" + startdate + "&enddate=" + enddate;
                var _fieldtitle = getLayuitablefield($(".layui-table th"));
                DownLoadFile({
                    url: url,
                    data: {
                        keyword: keyword, fieldtitle: _fieldtitle
                    }
                });
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                var index = layer.open({
                    title: 'Edit',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    area: ['700px', '90%'],
                    content: '/Log_Login/Edit?primarykey=' + data.Log_Id,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            }
        });

        table.on('sort(currentTableFilter)', function (obj) {
            reloadTable(obj.field, obj.type);
        });

        $('#btn-search').click(function () {
            reloadTable('Log_Id', 'asc');
            return false;
        });


        var _url = '/Log_Login/Search';
        table.render({
            elem: '#currentTableId',
            url: _url,
            toolbar: '#toolbarDemo',
            where: { sortField: 'Log_Id', sortType: 'asc' },
            defaultToolbar: ['filter'],
            cols: [[
                { type: "checkbox", width: 50 },

                { field: 'Log_UserName', width: 140, title: log_login_entity.Log_UserName },
                { field: 'Log_LoginIP', width: 120, title: log_login_entity.Log_LoginIP },
                { field: 'Log_IpAddress', width: 100, title: log_login_entity.Log_IpAddress },
                
                { field: 'Log_BrowserInfo', width: 500, title: log_login_entity.Log_BrowserInfo },
                
                {
                    field: 'Log_LoginTime', width: 200, title: log_login_entity.Log_LoginTime,  templet: function (d) {
                        return layuidatetimeFormatter(d.Log_LoginTime, "yyyy-MM-dd HH:mm:ss");
                    }},

                {
                    title: '操作', minWidth: 160, toolbar: '#currentTableBar', align: "center", fixed: 'right' },

            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true
        });
        reloadTable('Log_LoginTime', 'desc');
    });
</script>






